import { Component, OnInit, Input, forwardRef } from '@angular/core';
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';

@Component({
  selector: 'app-image-list-select',
  templateUrl: './image-list-select.component.html',
  styles: [],
  providers: [{
    provide: NG_VALUE_ACCESSOR,
    useExisting: forwardRef(() => ImageListSelectComponent),
    multi:true
  }]
})
export class ImageListSelectComponent implements OnInit, ControlValueAccessor {
  writeValue(obj: any): void {
    if (obj) {
      this.selecting = obj;
    }
  }
  registerOnChange(fn: any): void {
    this.propagateChange = fn;
  }
  registerOnTouched(fn: any): void {
    throw new Error("Method not implemented.");
  }
  setDisabledState?(isDisabled: boolean): void {
    throw new Error("Method not implemented.");
  }
  @Input()
  title: string;
  @Input()
  cols: number;
  @Input()
  rowHeight: number;
  svgIcons: string[];
  selectedIcon: string;
  propagateChange = (_: any) => { };
  selecting: string;
  constructor() { }

  ngOnInit() {
    let arr = [1, 2, 3, 4, 5, 6];
    this.svgIcons = arr.map(a => `avatar${a}`);
    let random = Math.floor(Math.random() * 5);
    this.selectedIcon = this.svgIcons[random];
    console.log(random);
  }
}
